package com.atguigu.controller;


import com.atguigu.common.Result;
import com.atguigu.pojo.User;
import com.atguigu.service.UserService;
import com.atguigu.service.impl.UserServiceImpl;
import com.atguigu.util.WebUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/userController")
public class UserController extends HttpServlet {
     //调用service
     private UserService userService=new UserServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id=Integer.parseInt(req.getParameter("id"));
        String userName=req.getParameter("userName");

        User user=new User();
        user.setId(id);
        user.setUserName(userName);

        int i = userService.saveUser(user);
        if(i==1){
            WebUtils.writeJson(Result.ok(),resp);
        }


    }
}
